﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Manage_ProductAdd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAdmin);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumCheckGoods);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        int i = 0;
        string SortId;
        SortId = SysFun.ToTrim(Request.Form["txtSortId"]);
        HZ.MBSM.Model.Product Product = new HZ.MBSM.Model.Product();

        HZ.MBSM.Model.Account Ac = (HZ.MBSM.Model.Account)Session["Account"];
        if (Ac != null)
        {
            int rowCun = 0;
            Db db1 = new Db();
            System.Data.IDataReader dr;
            string strSql = "select count(productid) as cun from product where  productcode='" + SysFun.ToTrim(txtProductCode.Text) + "' or ( ProductName='" + SysFun.ToTrim(txtProductName.Text) + "'  AND  Outlookc= '" + SysFun.ToTrim(txtOutlookC.Text) + "' AND Medicinemodel='" + SysFun.ToTrim(txtMedicinemodel.Text) + "' and xishu=" + SysFun.ToTrim(txtXiShu.Text) + ")";
            dr = db1.DataReader(strSql);
            if (dr.Read())
            {
                rowCun = SysFun.ToInt(dr["cun"]);
            }
            dr.Close();
            dr.Dispose();
            db1.Close();
            if (rowCun > 0)
            {
                Response.Write("<script language=JavaScript>alert('该商品在数据库中已经存在！！！');</script>");

            }
            else
            {

                Product.AccountId = Ac.AccountId;
                Product.AddDate = System.DateTime.Now;
                Product.IsMedicalCare = SysFun.ToBool(chkIsMedicalCare.Checked);
                Product.MedicalCareCode = txtMedicalCareCode.Text;
                Product.Medicinemodel = txtMedicinemodel.Text;
                Product.Outlookc = txtOutlookC.Text;
                Product.ProductName = txtProductName.Text;
                Product.Remark = txtRemark.Text;
                Product.SortId = SortId;
                Product.SpellingCode = HZ.MBSM.BLL.PYM.GetChineseSpell(Product.ProductName);
                Product.Unit = txtUnit.Text;
                Product.ProductCode = txtProductCode.Text;
                Product.XiShu = SysFun.ToInt(txtXiShu.Text);
                Product.HL = SysFun.ToFloat(txtHL.Text);
                Product.ZL = SysFun.ToFloat(txtZL.Text);

                HZ.MBSM.BLL.Product ProductAction = new HZ.MBSM.BLL.Product();
                i = ProductAction.InsertIntoProduct(Product);
                Response.Write("<script>alert('保存成功！！！');</script>");

                HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
                HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "插入", "Product", Product.ProductName + "|" + Product.ProductCode + "|" + Product.MedicalCareCode + "|" + Product.Medicinemodel + "|" + Product.Outlookc + "|" + Product.SortId + "|" + Product.XiShu, "../Magage/ProductAdd.aspx");


                Response.Write("<script>window.opener.location.reload();window.close();</script>");
            }
        }
        else
        {
            Response.Write("<script language=JavaScript>alert('您无权修改商品！！！');</script>");
        }
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Write("<script>window.close();</script>");
    }
}
